/****************************** Module Header ******************************\
* Module Name:	CppDllExport.h
* Project:		CppDllExport
* Copyright (c) Microsoft Corporation.
* 
* This sample Win32 DLL demonstrates exporting data, methods and classes for 
* use in C or C++ language executable. Two methods are used to export the 
* symbols:
* 
* 1. Export from a DLL using .def files
* 
* A module-definition (.def) file is a text file containing one or more  
* module statements that describe various attributes of a DLL. Create a .def 
* file and use the .def file when building the DLL. Using this approach, we 
* can export functions from the DLL by ordinal rather than by name. 
* 
* 2. Export from a DLL using __declspec(dllexport) 
* 
* __declspec(dllexport) adds the export directive to the object file so we do 
* not need to use a .def file. This convenience is most apparent when trying 
* to export decorated C++ function names. 
* 
* Examples
*  http://support.microsoft.com/kb/90530
*  http://msdn.microsoft.com/en-us/library/d91k01sh.aspx
*  http://msdn.microsoft.com/en-us/library/a90k134d.aspx
*  http://www.codeproject.com/KB/DLL/XDllPt1.aspx
* 
* This source is subject to the Microsoft Public License.
* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
* All other rights reserved.
* 
* History:
* * 1/21/2009 11:04 PM Jialiang Ge Created
\***************************************************************************/

#pragma once

#pragma region Includes
#include <windows.h>
#include <tchar.h>
#pragma endregion


// The following #ifdef block is the standard way of creating macros which 
// make exporting from a DLL simpler. All files within the DLL are compiled 
// with the CPPDLLEXPORT_EXPORTS symbol defined in preprocessor. The symbol 
// should not be defined on any project that uses this DLL. In this way any 
// other project whose source files include this file see SYMBOL_DECLSPEC 
// elements as being imported from a DLL, whereas this DLL sees symbols 
// defined with this macro as being exported.

#ifdef CPPDLLEXPORT_EXPORTS
#define SYMBOL_DECLSPEC __declspec(dllexport)
#define SYMBOL_DEF
#else
#define SYMBOL_DECLSPEC	__declspec(dllimport)
#define SYMBOL_DEF		__declspec(dllimport)
#endif


/////////////////////////////////////////////////////////////////////////////
// Export/Import data.
// 

// An exported/imported global data with a DEF file
// Sym: g_nVal1
// See: CppDllExport.def
//      CppDllExport.cpp
// Ref: http://support.microsoft.com/kb/90530


// A dllexport-ed/dllimport-ed global data
// Sym: g_nVal2
// See: CppDllExport.cpp
// Ref: http://support.microsoft.com/kb/90530
EXTERN_C SYMBOL_DECLSPEC int g_nVal2;


/////////////////////////////////////////////////////////////////////////////
// Export/Import methods.
// The default calling convention of the exported function is _cdecl 
// (See Project Properties -> C/C++ -> Advanced -> Calling Convention)
// 

// An exported/imported cdecl(default) method with a DEF file.
// Sym: HelloWorld
// See: CppDllExport.def
//      CppDllExport.cpp
// Ref: http://msdn.microsoft.com/en-us/library/d91k01sh.aspx
SYMBOL_DEF void /*__cdecl*/ HelloWorld(_TCHAR** pRet);

// An exported/imported stdcall method with a DEF file.
// Sym: stdcall_HelloWorld
// See: CppDllExport.def
//      CppDllExport.cpp
// Ref: http://msdn.microsoft.com/en-us/library/d91k01sh.aspx
SYMBOL_DEF void __stdcall stdcall_HelloWorld(_TCHAR** pRet);

// A dllexport-ed/dllimport-ed cdecl(default) method.
// Sym: Add
// See: CppDllExport.cpp
// Ref: http://msdn.microsoft.com/en-us/library/a90k134d.aspx
EXTERN_C SYMBOL_DECLSPEC int /*__cdecl*/ Add(int a, int b);

// A dllexport-ed/dllimport-ed stdcall method.
// Sym: _stdcall_Add@8
// See: CppDllExport.cpp
// Ref: http://msdn.microsoft.com/en-us/library/a90k134d.aspx
EXTERN_C SYMBOL_DECLSPEC int __stdcall stdcall_Add(int a, int b);

// A dllexport-ed/dllimport-ed cdecl(default) method without extern "C".
// Sym: ?Div@@YANNN@Z
// See: CppDllExport.cpp
SYMBOL_DECLSPEC float /*__cdecl*/ Div(float a, float b);

// A dllexport-ed/dllimport-ed stdcall method without extern "C".
// Sym: ?stdcall_Div@@YGNNN@Z
// See: CppDllExport.cpp
SYMBOL_DECLSPEC float __stdcall stdcall_Div(float a, float b);

// A dllexport-ed/dllimport-ed stdcall method with a DEF file (Because of the
// DEF file, the naming convention of stdcall is removed in the exported 
// symbol). It requires callback as one of the arguments.
// Sym: Max 
// See: CppDllExport.cpp
typedef int (CALLBACK *PFN_COMPARE)(int, int);
EXTERN_C SYMBOL_DECLSPEC int __stdcall Max(int a, int b, PFN_COMPARE cmpFunc);


/////////////////////////////////////////////////////////////////////////////
// Export/Import class.
// 

// A dllexport-ed/dllimport-ed class.
// It exports/imports all of the public data members and the methods.
// Sym: ??0CppSimpleClass@@QAE@XZ
// See: CppDllExport.cpp
// Ref: http://msdn.microsoft.com/en-us/library/a90k134d.aspx
class SYMBOL_DECLSPEC CppSimpleClass
{
private:
	float m_fField;

public:
	// Constructor
	CppSimpleClass();

	// Public method
	float Increment(float fVal);
};